<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Base\Annotation\Common;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\AdminUserRepository")
 */
class AdminUser
{
    /**
     * @Common(cnName="#",listType="text",editType="text")
     * @Groups({"edit"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Common(cnName="账号",listType="text",editType="text")
     * @Groups({"edit"})
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @Common(cnName="密码",listType="text",editType="text")
     * @Groups({"edit"})
     * @ORM\Column(type="string", length=255)
     */
    private $password;

    /**
     * @Common(cnName="添加时间",listType="text",editType="text")
     * @Groups({"edit"})
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $createAt;

    /**
     * @Common(cnName="是否启用",listType="switch",editType="text")
     * @Groups({"edit"})
     * @ORM\Column(type="boolean")
     */
    private $enable;

    /**
     * @Common(cnName="分组",listType="text",editType="text")
     * @Groups({"edit"})
     * @ORM\ManyToMany(targetEntity="App\Entity\AdminGroup", inversedBy="users")
     */
    private $groups;

    /**
     * @Common(cnName="名称",listType="text",editType="text")
     * @Groups({"edit"})
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $nickName;

    public function __construct()
    {
        $this->groups = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function setPassword(string $password): self
    {
        $this->password = $password;

        return $this;
    }

    public function getCreateAt(): ?\DateTimeInterface
    {
        return $this->createAt;
    }

    public function setCreateAt(?\DateTimeInterface $createAt): self
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getEnable(): ?bool
    {
        return $this->enable;
    }

    public function setEnable(bool $enable): self
    {
        $this->enable = $enable;

        return $this;
    }

    /**
     * @return Collection|AdminGroup[]
     */
    public function getGroups(): Collection
    {
        return $this->groups;
    }

    public function addGroup(AdminGroup $group): self
    {
        if (!$this->groups->contains($group)) {
            $this->groups[] = $group;
        }

        return $this;
    }

    public function removeGroup(AdminGroup $group): self
    {
        if ($this->groups->contains($group)) {
            $this->groups->removeElement($group);
        }

        return $this;
    }

    public function getNickName(): ?string
    {
        return $this->nickName;
    }

    public function setNickName(?string $nickName): self
    {
        $this->nickName = $nickName;

        return $this;
    }
}
